def getdivisors(n):
	divs = []
	for x in range(1,n):
		if n % x == 0:
			divs.append(x)
	return divs

def amic(n):
	return sum(getdivisors(n))

total = 0

for x in range(1,10000):
	if amic(amic(x)) == x:
		if(amic(x) < 10000):
			if amic(x) != x:
				total = total + x


print(total)